package pl.freetimetool.view.editor;

import java.beans.PropertyEditorSupport;

import pl.freetimetool.domain.Manager;
import pl.freetimetool.service.AccountService;

public class ManagerEditor extends PropertyEditorSupport {

	final AccountService accountService;

	public ManagerEditor(final AccountService accountService) {
		this.accountService = accountService;
	}

	@Override
	public void setAsText(final String text) throws IllegalArgumentException {
		this.setValue(this.accountService.getAccount(text));
	}

	@Override
	public String getAsText() {
		final Manager manager = (Manager) this.getValue();
		if (manager == null) {
			return null;
		} else {
			return manager.getUsername();
		}
	}
}
